//2009/10/24 02:26:16
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class DigitsSum
{
public:
    int lastDigit(int n)
    {
		string s = convertIntegerToString(n);
		while(s.size() > 1)
		{
			cout << s << endl;
			int sum = 0;
			for(int i=0; i<s.size(); i++)
				sum += s[i] - '0';
			cout << "Sum: " << sum << endl;
			s.clear();
			s = convertIntegerToString(sum);
		}
		int ret = convertStringToInteger(s);
		return ret;
    }
    string convertIntegerToString(int number)
    {
        stringstream s;			//create a stringstream
        s << number;				//add number to the stream
        return s.str();			//return a string with the contents of the stream
    }
// Convert String to Integer;
    int convertStringToInteger(string s)
    {
        stringstream ss(s);
        int number;
        ss >> number;
        return number;
    }
};
